﻿//-----------------------------------------------------------------------
// <copyright file="EditorCoolHelper.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.DomainObjects.XmlFeedObjects
{
    using System.Linq;
    using System.Xml.Linq;

    using ChatBox.DomainObjects.ResultData;

    /// <summary>
    /// Helper methods for EditorCool
    /// </summary>
    public static class EditorCoolHelper
    {
        /// <summary>
        /// read editor cools from an xml document
        /// </summary>
        /// <param name="doc">the xml document</param>
        /// <returns>the editor cools</returns>
        public static EditorCoolsDataResult ToEditorCools(this XContainer doc)
        {
            EditorCoolsDataResult result = new EditorCoolsDataResult(true, string.Empty, null);

            var coolWriteups = doc.Element("editorcools");

            var nodeList = coolWriteups.Elements("edselection");

            var editorCoolsQuery =
                from node in nodeList
                select new EditorCool
                   {
                       CooledBy = node.Element("endorsed").ToLink(),
                       Writeup = node.Element("e2link").ToLink()
                   };

            result.EditorCools = editorCoolsQuery.ToList();
            return result;
        }
    }
}
